全部学科
Python全栈
python
NodeJS全栈
nodejs
📅 2026-05-11 6 分钟 ✍️ juanwangdev

git clone 克隆仓库

git clone 命令将远程仓库完整复制到本地,包含所有历史记录。

基本用法

Bash
# 克隆远程仓库
git clone <url>

# 克隆到指定目录名
git clone <url> <directory>

# 克隆 GitHub 仓库
git clone https://github.com/user/repo.git
git clone git@github.com:user/repo.git

克隆示例

Bash
# HTTPS 方式
git clone https://github.com/vuejs/vue.git

# SSH 方式
git clone git@github.com:vuejs/vue.git

# 指定目录名
git clone https://github.com/vuejs/vue.git my-vue

克隆方式对比

方式URL 格式特点
HTTPShttps://github.com/user/repo.git简单通用,需输入密码
SSHgit@github.com:user/repo.git需配置密钥,免密操作
Gitgit://github.com/user/repo.git只读,较少使用

常用选项

Bash
# 浅克隆(只取最近一次提交,节省空间)
git clone --depth 1 <url>

# 克隆指定分支
git clone -b <branch> <url>

# 克隆到指定目录
git clone <url> <directory>

# 裸克隆(无工作区)
git clone --bare <url>

克隆后目录结构

Bash
project/
├── .git/          # Git 仓库目录
├── .gitignore     # 忽略规则文件
├── README.md      # 说明文件
└── src/           # 源代码目录

克隆会自动创建远程仓库名的同名目录,并自动设置 origin 远程源。

要点总结

  1. git clone <url> 克隆远程仓库到本地
  2. 支持 HTTPS、SSH、Git 协议
  3. --depth 1 浅克隆,节省空间和时间
  4. -b <branch> 克隆指定分支
  5. 克隆后自动设置 origin 远程源
想在手机上练习这篇文章的配套题目?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码
← 上一篇 git clean 清理未跟踪文件
下一篇 → git commit 提交更改
扫码体验小程序
加载中
想在手机上刷题学习?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码